#include "Server.h"
#include <iostream>
#include <chrono>


net::Server::Server()
{
	std::cout << "Server has been created" << std::endl;
	_isRunning = true;
	_thread = new std::thread(&net::Server::Run, this);
}


net::Server::~Server()
{
	_isRunning = false;
	if (_thread != nullptr)
	{
		_thread->join();
	}

	std::cout << "Server has been stopped and terminated" << std::endl;
}

void net::Server::Run()
{
	std::cout << "Server thread started" << std::endl;
	while (_isRunning)
	{
		std::this_thread::sleep_for(std::chrono::seconds(1));
		std::cout << "Server iteration" << std::endl;
	}

	std::cout << "Server thread stopped" << std::endl;
}